package com.cn.crmsystem.controller.businessController;

import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.Problem;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.service.businessService.ProblemService;
import io.swagger.annotations.*;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@Api(value = "常见问题",tags ="常见问题接口API" )
public class AllProblemController {
    @Autowired
    private ProblemService problemService;

    /**
     * 查询所有常见问题
     * @param map
     * @return
     */
    @RequestMapping(value = "/selectProbleAll",method = RequestMethod.POST)
    @ApiOperation(value = "查询所有常见问题接口",notes = "业务员管理员操作",httpMethod = "POST",response = ResultJson.class)
   @ApiImplicitParams({
           @ApiImplicitParam(name = "problem_id",value = "常见问题编号",paramType = "query",dataType = "problem",required = false),
           @ApiImplicitParam(name = "problem_title",value = "常见问题标题",paramType = "query",dataType = "problem",required = false),
           @ApiImplicitParam(name = "problem_type",value = "常见问题类型（0：业务咨询，1：售后问题，2：售前问题，3：投诉问题）",paramType = "query",dataType = "problem",required = false),
           @ApiImplicitParam(name = "create_id",value = "创建人id",paramType = "query",dataType = "problem",required = false),
           @ApiImplicitParam(name = "creation_time",value = "创建时间",paramType = "query",dataType = "problem",required = false),
   })
    public ResultJson selectProblemAll(@RequestBody
        @ApiParam(name = "map",value = "{problem_id 常见问题编号(int)," +
                "problem_title 常见问题标题(String)," +
                "problem_type 常见问题类型（0：业务咨询，1：售后问题，2：售前问题，3：投诉问题）(int)," +
                "problem_content 常见问题内容(int)," +
                "create_id 创建人id(int)," +
                "creation_time 创建时间(date)," +
                "delete_state 删除状态（0:显示，1：隐藏）(int)"+
                "}")
        Map map){
        return problemService.selectProblemAll(map);
    }

    @RequestMapping(value = "/selectProblemById",method = RequestMethod.POST)
    @ApiOperation(value = "根据ID查询常见问题接口",notes = "业务员管理员操作",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "常见问题编号",required = true,dataType = "problem",paramType = "query")
    public ResultJson selectProblemById(@ApiParam(name = "problem",value = "根据ID查询常见问题") Integer id){
        return  problemService.selectProblemById(id);
    }

    @RequestMapping(value = "/addProblem",method = RequestMethod.POST)
    @ApiOperation(value = "新增常见问题接口",notes = "业务员操作",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "problem_title",value = "常见问题标题",required = true,dataType = "problem",paramType = "query")
    public  ResultJson addProblem(@RequestBody @ApiParam(name = "problem",value = "新增常见问题") Problem problem){
        Login login = (Login) SecurityUtils.getSubject().getPrincipal();
        System.out.println(login);
        return problemService.addProblem(problem,login);
    }

    @RequestMapping(value = "/updateProblem",method = RequestMethod.POST)
    @ApiOperation(value = "根据ID修改常见问题接口",notes = "管理员操作",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "常见问题编号",required = true,dataType = "problem",paramType = "query")
    public  ResultJson updateProblem(@ApiParam(name = "prblem",value = "根据ID修改常见问题") Integer id){

        return problemService.updateProblem(id);
    }

    @RequestMapping(value = "/deleteByIdProblem",method = RequestMethod.POST)
    @ApiOperation(value = "删除（修改接口）",notes="管理人员操作",httpMethod ="POST",response = ResultJson.class)
    public ResultJson deleteByIdProblem(@ApiParam(name = "id",value = "根据ID删除") Integer id){
        System.out.println("*******");
        System.out.println(id);
        return problemService.deleteByIdProblem(id);
    }
}
